# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=fernflower
pkgver=814.2433feb3
pkgrel=1
pkgdesc='An analytical decompiler for Java.'
groups=('blackarch' 'blackarch-decompiler')
arch=('any')
url='https://github.com/fesh0r/fernflower'
license=('Apache')
depends=('jdk17-openjdk')
makedepends=('git' 'jdk17-openjdk' 'gradle')
source=("git+https://github.com/fesh0r/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

build() {
  cd $pkgname

  ./gradlew
  ./gradlew build
  ./gradlew jar
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"

  install -Dm 644 build/libs/fernflower.jar \
    "$pkgdir/usr/share/$pkgname/fernflower.jar"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md

cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
exec java -jar /usr/share/$pkgname/$pkgname.jar "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

